import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class iframePosition:
    # def __init__(self, driver):
    #     self.driver = driver

    def get_iframe_position(self):
        # iframe = self.driver.find_element(By.ID, iframe_id)
        # iframe_location = iframe.location
        # return iframe_location

        chrome_path = r'C:\Program Files\Google\Chrome\Application\chromedriver.exe'

        # chrome_options = webdriver.ChromeOptions()
        # chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])

        chrome_service = ChromeService(executable_path=chrome_path)

        # chrome_driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
        chrome_driver = webdriver.Chrome(service=chrome_service)

        chrome_driver.maximize_window()
        chrome_driver.get('https://126.com/')
        time.sleep(3)

        iframe = WebDriverWait(chrome_driver,3).until(
            EC.presence_of_element_located((By.XPATH, '//*[@id="loginDiv"]/iframe'))
        )
        # 切换到iframe
        chrome_driver.switch_to.frame(iframe)



        input_username = WebDriverWait(chrome_driver,10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,'.j-inputtext.dlemail.j-nameforslide'))
        )
        input_username.send_keys('1234')


        # chrome_driver.find_element(By.CLASS_NAME,'j-inputtext dlemail j-nameforslide').send_keys('123456')
        chrome_driver.find_element(By.CSS_SELECTOR,'.j-inputtext.dlpwd').send_keys('123456')
        time.sleep(3)

if __name__ == '__main__':
    iframePosition().get_iframe_position()